package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.google.gson.JsonObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "分类管理")
@RestController
@RequestMapping(value = "/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {

    @Resource
    private BaseCategoryService baseCategoryService;

    @GetMapping("getBaseCategoryList")
    @Operation(summary = "获取分类列表")
    public Result<List<JSONObject>> getBaseCategoryList() {
        List<JSONObject> result = baseCategoryService.getBaseCategoryList();
        return Result.ok(result);
    }

    @GetMapping("findAttribute/{category1Id}")
    @Operation(summary = "根据一级分类id获取专辑标签")
    public Result<List<BaseAttribute>> findAttribute(@PathVariable Long category1Id) {
        List<BaseAttribute> baseAttributes = baseCategoryService.findAttribute(category1Id);
        return Result.ok(baseAttributes);
    }

    @GetMapping("findBaseCategoryView/{category3Id}")
    @Operation(summary = "根据三级分类id获取专辑标签值")
    public Result<BaseCategoryView> findBaseCategoryView(@PathVariable Long category3Id) {
        BaseCategoryView baseCategoryView = baseCategoryService.findBaseCategoryView(category3Id);
        return Result.ok(baseCategoryView);
    }

    @GetMapping("findTopBaseCategory3/{category1Id}")
    @Operation(summary = "根据一级分类id获取热门三级分类")
    public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id) {
        List<BaseCategory3> baseCategory3List = baseCategoryService.findTopBaseCategory3(category1Id);
        return Result.ok(baseCategory3List);
    }

    @GetMapping("/getBaseCategoryList/{category1Id}")
    @Operation(summary = "根据一级分类id获取所有分类")
    public Result<JSONObject> getBaseCategoryList(@PathVariable Long category1Id) {
        JSONObject result = baseCategoryService.getBaseCategoryList(category1Id);
        return Result.ok(result);
    }
}

